<?php
/**
 * This file contains feed related functions.
 *
 * @author Nathan Rice
 * @package Prodigy
 **/

/**
 * This function redirects the browser to the feedburner URL
 *
 * @uses wp_redirect
 * @uses prodigy_option
 *
 * @since 0.1
 */
add_action('template_redirect','prodigy_feed_redirect');
function prodigy_feed_redirect() {
	global $feed;
	$feedburner_url = prodigy_option('feedburner_url');
	
	if (!preg_match("/feedburner|feedvalidator/i", $_SERVER['HTTP_USER_AGENT'])) {
		if(is_feed() && $feed != 'comments-rss2' && get_query_var('category_name') == '' && $feedburner_url)
		wp_redirect($feedburner_url, 302);
	}
}

/**
 * This function replaces the default feed link with
 * the custom feedburner URL supplied by the user by
 * filtering feed_link.
 *
 * @uses prodigy_option
 *
 * @since 0.1
 */
add_filter('feed_link','prodigy_feed_link', 1, 2);
function prodigy_feed_link($output, $feed) {
	$feedburner_url = prodigy_option('feedburner_url');
	
	if($feed != 'comments-rss2' && $feedburner_url)
	$output = $feedburner_url;
	
	return $output;
}
?>